package model

import (
	"gorm.io/gorm"
	"micro-chat/config"
	"time"
)

type Blacklist struct {
	Id          uint32         `gorm:"column:id;type:int UNSIGNED;comment:黑名单ID;primaryKey;not null;" json:"id"`                                 // 黑名单ID
	UserId      int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" json:"user_id"`                                            // 用户ID
	BlackUserId int32          `gorm:"column:black_user_id;type:int;comment:被拉黑用户ID;not null;" json:"black_user_id"`                             // 被拉黑用户ID
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);comment:拉黑时间;not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 拉黑时间
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);comment:更新时间;not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"` // 更新时间
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (b *Blacklist) TableName() string {
	return "blacklist"
}

// 添加黑名单
func (b *Blacklist) AddList() error {
	return config.DB.Create(&b).Error
}

// 查看黑名单
func (b *Blacklist) FindBlackList(id int32) (list []*Blacklist, err error) {
	err = config.DB.Where("user_id = ?", id).Find(&list).Error
	return
}
